Learning Goals

By the end of this activity, you will be able to:

1. Start the cotainerized cluster. If you paused your containers in the previous Hands On module, go through the steps 3-5 of the previous module to start the containerized cluster.

2. Exploring MapReduce applications. Hadoop comes with several MapReduce applications These applications are located in share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar.

Run yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar to display them.

yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar 

We can learn how to run any application by examining its command-line arguments. Let's take for example pi

Run yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar pi

yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar pi

3. Running a first MapReduce example. We will start by running pi as our first example.

Run yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar pi 10 15

yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar pi 10 15

Once the job is completed, you should see a result like the following:

Furthermore, this process created the HDFS user folder automatically, so we don't need to go again through that step.

4 . See WordCount command line arguments. Run yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar wordcount

yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar wordcount

5. Run WordCount. If you started a new session, make sure to place the words.txt file into the HDFS. You can either copy the file ( hdfs dfs -copyFromLocal words.txt ) or run hdfs dfs -put words.txt which will directly place the file into HDFS.

hdfs dfs -copyFromLocal words.txt

Run yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar wordcount words.txt out

yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar wordcount words.txt out

6 . See WordCount output directory. Once WordCount is finished, let's verify the output was created. First, let's see that the output directory, out, was created in HDFS by running hdfs dfs –ls

hdfs dfs -ls

We can see there are now two items in HDFS: words.txt is the text file that we previously created, and out is the directory created by WordCount.

7 . Look inside output directory. The directory created by WordCount contains several files. Look inside the directory by running hdfs dfs -ls out

hdfs dfs -ls out

The file part-r-00000 contains the results from WordCount. The file _SUCCESS means WordCount executed successfully.

8 . Copy WordCount results to local file system. Copy part-r-00000 to the namenode-1 container file system by running hdfs dfs -copyToLocal out/part-r-00000 local.txt

hdfs dfs -copyToLocal out/part-r-00000 local.txt

9. Exit the container. Run exit to return to your local system terminal shell.

exit

9. View the WordCount results. Run docker cp hadoop-namenode-1:/opt/hadoop/local.txt ./local.txt to copy the text file into your local system.

docker cp hadoop-namenode-1:/opt/hadoop/local.txt ./local.txt

Go to your big-data-1/hadoop directory and open the text file to view the results using your system's text editor (Notepad for Windows or TextEdit for macOS).

Each line of the results file shows the number of occurrences for a word in the input file. For example, Amen appears twice in the input, but Aroint appears only once. Keep in mind that we did not pre process the words, so that's why you see some repeated words, where the application identifies them a different given an additional character (like "Brutus" vs "Brutus,").

10. Delete the container. If you're planning to come back to the course later, run docker compose down to delete all your containers. If you're planning to go to the Quiz from here, do not delete the containers and go directly to the Quiz.